<?php
//控件
import('~base.interface.IControl');
import('~base.factory.TemplateFactory');
class BaseControl implements IControl
{
	protected $id;
	protected $templatePath;
	protected $data;
	
	public function __construct($id = '', $templatePath = '', $data = null)
	{
		if($id) $this->setId($id);
		if($templatePath) $this->setTemplatePath($templatePath);
		if($data) $this->setData($data);
	}
	
	public function setId($id)
	{
		$this->id = $id;
	}
	public function getId()
	{
		return $this->id;
	}
	
	public function setTemplatePath($templatePath)
	{
		$this->templatePath = $templatePath;
	}
	public function getTemplatePath()
	{
		return $this->templatePath;
	}
	
	public function setData($data)
	{
		$this->data = $data;
	}
	public function getData()
	{
		return $this->data;
	}
	
	public function render($isReturn = false)
	{
		$template = TemplateFactory::create();
		
		if($isReturn)
		{
			return $template->display($this->getTemplatePath(), $this->getData(), $isReturn);
		}
		else
		{
			echo $template->display($this->getTemplatePath(), $this->getData(), $isReturn);
		}
	}
}
?>